package kr.hkit.powerjava.chapter21.work;

import java.util.*;

class ExceptionEx {
	public static void main(String[] args) {
		int[] list;
		int sum = 0;
		int count =0 ;
		
		Scanner sc = new Scanner(System.in);
		System.out.print("정수의 갯수는 : ");
		
		try{
			count = sc.nextInt();
			list = new int[count];
	
			System.out.print("정수를 입력하세요 : ");
	
			for (int i = 0; i < count; i++) {
				list[i] = sc.nextInt();
				if (list[i] < 0) {
					throw new ArithmeticException();
				}
			}
			for (int i = 0; i < count; i++) {
				sum += list[i];
			}
		}catch(ArithmeticException e){
			e.printStackTrace();
		}catch(NegativeArraySizeException e){
			e.printStackTrace();
		}catch(ArrayIndexOutOfBoundsException e){
			e.printStackTrace();
		}catch(NullPointerException e){
			e.printStackTrace();
		}

		System.out.println("평균은 : " + sum / count);
	}
}


